function [report,flagStru]=reportPositions(report,names,sampleStru) 

%% reportCheck works with the old names of the nameStru 
%  This function works instead with 
%  *names.states* 

%% I. Inputs
%
%% I.a) *report* structure can contain following fields 
% 
% 1) *.stateMom*, will be usded for all moments (stds and cross-correlations)
% including variance decompositions, and also Historical Decompositions 
%
% 2) *.stateIRF*, Impulse responses. Can be of the form <name> + 'lev',
% which indicates IRF should be added. 
%
% 3) *.stateSpectrum*  only for the spectral decomposition. Can also
% contain <name> + 'lev'. 
% 
% 4) *.subSamples* [NB NC] cell array with dates at which the sub-samples
% start in column 1 and subsample ends in column 2. Leave empty if there
% are no subsamples. This will be used in the historical analysis to zoom
% into particular episodes. 
% 
% 5) *.stateDecomp* cell with the states that will be decomposed 
% 
%% I.b) *nameStru* structure must contain *.stateNames*
% 
%% I.c) *sampleStru* must contain *.sampleVec*
%
%% II. Output 
% 
%% II.a) Append to report 
%
% < >Pos with row Position of each element 
% 
%% If subSamples, also assign 
%
% *.subSampleN:* [NB 1] vector with the lengths of the sub-samples 
%
% *.subSamplePos:* [NB 2] matrix with the position at which each sample
%  begings and ends 
%
% *.subSampleCell:* [NB 1] cell with the names of the subsamples in string
%  form 

%% II.b) flagStru ==1 for each field that exists 



%% *report*
%
%% 1. stateDecomp
if isfield(report,'stateDecomp')==false || isempty(report.stateDecomp); 
    disp('No States to decompose'); 
    flagStru.stateDecomp=false; 
else 
    disp('States to Decompose');
    printcell(report.stateDecomp(:));
    report=...
        setfield(report,'stateDecompPos',cellposition(report.stateDecomp(:),names.states,1)); 
    flagStru.stateDecomp=true;
end 
%
%% 2. stateSpectrum
if isfield(report,'stateSpectrum')==false || isempty(report.stateSpectrum); 
    disp('No States for Spectrum');
    flagStru.stateSpectrum=false;
else 
    disp('States to for Spectrum'); 
    printcell(report.stateSpectrum(:)); 
    [tempPos,tempAdd]=extractlevels(report.stateSpectrum,names.states); 
    report=setfield(report,'stateSpectrumPos',tempPos);
    report=setfield(report,'stateSpectrumPosAdd',tempAdd);
    flagStru.stateSpectrum=true; 
end 
%
%% 3. stateIRF
if isfield(report,'stateIRF')==false || isempty(report.stateIRF); 
    disp('No States for IRF');
    flagStru.stateIRF=false;
else 
    disp('States to for IRF'); 
    printcell(report.stateIRF(:)); 
    flagStru.stateIRF=true; 
    [tempPos,tempAdd]=extractlevels(report.stateIRF,names.states); 
    report=setfield(report,'statePosIRF',tempPos);
    report=setfield(report,'addStateIRF',find(tempAdd~=0));

end 
%
%% 4. stateMom
if isfield(report,'stateMom')==false || isempty(report.stateMom); 
    disp('No States for Mom');
    flagStru.stateMom=true;
else 
    disp('States to for Mom'); 
    printcell(report.stateMom(:)); 
    flagStru.stateMom=true; 
    report=...
    setfield(report,'statePosMom',cellposition(report.stateMom(:),names.states,1)); 
end
%
%% 5. subSamples report.sampleVec=sampleStru.sampleVec;
if isfield(report,'subSamples')==false || isempty(report.subSamples)==true;
    disp('No Subsamples to report in historical decomposition')
    flagStru.subSamples=false;
    return
else
    disp('Subsamples for Report')
    report.sampleVec=sampleStru.sampleVec;
    printcell(report.subSamples);
    flagStru.subSamples=true;
    report=sampleAssignments(report,1);
    flagStru.subSamples=true;
end 